﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Grain.Crm.DataMigrator.Infrastructure
{
    public class Container : List<ContainerEntry>
    {
        public void Build(Builder builder)
        {
           builder.Build(this);
        }

        public string GetByKey(string key)
        {
            var entry = this.FirstOrDefault(e => e.Key == key);
            if(entry == null)
                throw new KeyNotFoundException("Container value was not found by key=" + key);

            if (entry.ResolvedValue == null)
                entry.ResolvedValue = entry.Value.Resolve();

            return entry.ResolvedValue;
        }
    }

    public class ContainerEntry
    {
        public string Key { get; set; }
        public ValueResolver Value { get; set; }

        public string ResolvedValue { get; set; }
    }
}
